/*
 * @lc app=leetcode.cn id=937 lang=javascript
 *
 * [937] 重新排列日志文件
 */

// @lc code=start
/**
 * @param {string[]} logs
 * @return {string[]}
 */
var reorderLogFiles = function (logs) {
    let a = []
    let b = []
    logs.forEach((item) => {
        if (isNaN(item[item.length - 1])) {
            a.push(item)
        } else {
            b.push(item)
        }
    })

    a.sort((a, b) => {
        let temp = a.substr(0, a.indexOf(" "))
        a = (a.slice(a.indexOf(" ")) + temp).trim()
        temp = b.substr(0, b.indexOf(" "))
        b = (b.slice(b.indexOf(" ")) + temp).trim()
        return a >b?1:-1//此处很关键，返回a>b没用，必须大于返回1，小于返回-1
    })
    return a.concat(b)
};
// @lc code=end

